# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
import os
import scrapy
from douyucdn.settings import IMAGES_STORE as images_store
from scrapy.pipelines.images import ImagesPipeline

class DouyucdnPipeline(ImagesPipeline):
    def get_media_requests(self,item,info):
        vertical_src = item["vertical_src"]
        yield scrapy.Request(vertical_src)

    def item_completed(self,results,item,info):
        image_path = [x["path"] for ok,x in results if ok]
        nickname = item["nickname"]
        os.rename(images_store+image_path[0],images_store + nickname+".jpg")
